﻿using PropertyChanged;
using System.Collections.ObjectModel;
using VIA.Integration.Domain.Production;
using VIA.Presentation;
using VIA.Presentation.Contracts;

namespace VIA.UVInkjetPrint.Presentation.ViewModel
{
    [ViewModel(typeof(IStationResultView))]
    internal class StationResultViewModel : ViewModel<IStationResultView>
    {
        IProduct _current;
        protected IDispatcherService _dispatcherService;
        private string barcode;
        private PrintImageViewModel topPrintImage;
        private PrintImageViewModel sideImage1;
        private PrintImageViewModel sideImage2;

        public IProduct Product { get => _current; set => SetProperty(ref _current, value); }
        public string Barcode { get => barcode; set => SetProperty(ref barcode, value); }
        public ObservableCollection<PrintImageViewModel> TopPrintImages { get; set; } = new();
        public ObservableCollection<PrintImageViewModel> SideImages1 { get; set; } = new();
        public ObservableCollection<PrintImageViewModel> SideImages2 { get; set; } = new();

        public PrintImageViewModel TopPrintImage { get => topPrintImage; set => SetProperty(ref topPrintImage, value); }
        public PrintImageViewModel SideImage1 { get => sideImage1; set => SetProperty(ref sideImage1, value); }
        public PrintImageViewModel SideImage2 { get => sideImage2; set => SetProperty(ref sideImage2, value); }

        public StationResultViewModel( IDispatcherService dispatcherService)
        {
            _dispatcherService = dispatcherService;
        }

        private void ProductionLine_ProductionCompleted(object? sender, ProductionEventArgs<IProduct> e)
        {
            this.View.Dispatcher.InvokeAsync(() =>
            {
            });
        }

        private void ProductionLine_ProductionStart(object? sender, ProductionEventArgs<IProduct> e)
        {
            this.View.Dispatcher.InvokeAsync(() =>
            {
            });
        }
    }

    [AddINotifyPropertyChangedInterface]
    internal class PrintImageViewModel
    {
        public int Index { get; set; }

        public ImageDetectionResult Result { get; set; }

        public PrintImageViewModel(ImageDetectionResult result, int index)
        {
            Result = result;
            Index = index;
        }
    }
}
